import lejos.nxt.*;
/**
 * A simple line follower for the LEGO 9797 car with
 * a light sensor. Before the car is started on a line
 * a BlackWhiteSensor is calibrated to adapt to different
 * light conditions and colors.
 * 
 * The light sensor should be connected to port 3. The
 * left motor should be connected to port C and the right 
 * motor to port B.
 * 
 * @author  Ole Caprani
 * @version 23.08.07
 */
public class LineFollowerCal
{
  public static void main (String[] aArg)
  throws Exception
  {
     final int power = 95;
     int turn_counter = 0;
     int green_count = 0;	
     int last_value_l = 0;
     int last_value_r = 0;
     int back_to_track = 0; // 0 = left, 1 = right
     
//     ColorSensor sensor_l = new ColorSensor(SensorPort.S3);
//     ColorSensor sensor_r = new ColorSensor(SensorPort.S2);
//	 
//     sensor_l.calibrate();
//     sensor_r.copyCalibration(sensor_l);
	 
     LCD.clear();
     LCD.drawString("Light: ", 0, 2); 
     while( !Button.ENTER.isPressed() );
     
     while (! Button.ESCAPE.isPressed())
     {
//	     LCD.drawInt(sensor_l.light(),4,10,2);
//	     LCD.drawInt(sensor_r.light(), 4, 10, 3);
	     
	     LCD.refresh();
	     
	     	Car.forward(power, power);
	     	Thread.sleep(2000);
	     	Car.forward(power, power-10);
	     	Thread.sleep(2150);
	     	Car.forward(power, 80);
	     	Thread.sleep(3600);
	     	Car.forward(power, power);
	     	Thread.sleep(2000);
	     	Car.forward(power, power-10);
	     	Thread.sleep(2150);
	     	Car.forward(80, power);
	     	Thread.sleep(3400);
	     	Car.stop();
	     	Thread.sleep(3000);
	       	 
	     Thread.sleep(10);
     }
     
     Car.stop();
     LCD.clear();
     LCD.drawString("Program stopped", 0, 0);
     LCD.refresh();
   }
}

